﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace DentalSoftware
{
    public partial class PhieuThu : Form
    {
        private double soTien;

        public double SoTien
        {
            get { return soTien; }
            set { soTien = value; }
        }

        public PhieuThu()
        {
            InitializeComponent();
            txtMaPhieu.Text = ThuChiBUS.GetMaxMa().ToString();
        }

        public PhieuThu(DateTime ngay, string nth, string dc, string dt, string nd)
        {
            InitializeComponent();

            txtDiaChi.Text = dc;
            mtbDienThoai.Text = dt;
            txtNguoiNopTien.Text = nth;
            dtpNgay.Value = ngay;
            txtNoiDung.Text = nd;
            txtMaPhieu.Text = ThuChiBUS.GetMaxMa().ToString();

            txtNoiDung.Enabled = false;
            txtNguoiNopTien.Enabled = false;
            dtpNgay.Enabled = false;
            mtbDienThoai.Enabled = false;
            txtDiaChi.Enabled = false;
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            PhieuThuChiDTO ptc = new PhieuThuChiDTO();
            ptc.Ngay = new DateTime(dtpNgay.Value.Year, dtpNgay.Value.Month, dtpNgay.Value.Day);
            ptc.Nguoithuchien = txtNguoiNopTien.Text;
            ptc.Diachi = txtDiaChi.Text;
            ptc.Dienthoai = mtbDienThoai.Text;
            ptc.Noidung = txtNoiDung.Text;
            ptc.Sotien = float.Parse(mtbSoTien.Text);
            ptc.Loai = 1;

            ThuChiBUS.InsertPhieu(ptc);

            soTien = ptc.Sotien;

            this.DialogResult = DialogResult.Yes;
            this.Close();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }
    }
}
